package com.example.a14110100409.yuejiandemo.fragment;

import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.a14110100409.yuejiandemo.R;
import com.example.a14110100409.yuejiandemo.adapter.ClubListAdapter;
import com.example.a14110100409.yuejiandemo.adapter.TrainListAdapter;
import com.example.a14110100409.yuejiandemo.javabean.Train;
import com.example.a14110100409.yuejiandemo.javabean.TrainInfo;
import com.example.a14110100409.yuejiandemo.model.TrainModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class TrainAllFragment extends Fragment {
    private RecyclerView recyclerView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.activity_train_all_fragment,container,false);
        recyclerView = (RecyclerView) view.findViewById(R.id.trainall_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局
        showData();
        return view;
    }
    private void showData(){
        TrainModel trainModel = new TrainModel();
        Call<List<TrainInfo>> call = trainModel.gettrainlists();
        call.enqueue(new Callback<List<TrainInfo>>() {
            @Override
            public void onResponse(Call<List<TrainInfo>> call, Response<List<TrainInfo>> response) {
                List<TrainInfo> mDataList = response.body();
                recyclerView.setAdapter(new TrainListAdapter(TrainAllFragment.this.getContext(),mDataList));//设置适配器，绑定Adapter.
            }

            @Override
            public void onFailure(Call<List<TrainInfo>> call, Throwable t) {

            }
        });
    }

}
